package com.smartjobs.action;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.util.RuntimeSettings;

import d2rq.dump_rdf;

public class PublishRDFAction extends ActionSupport implements
ServletRequestAware{
	
	public HttpServletRequest request;
	
	public String execute()
	{
		System.out.println("here inside publish action");
		String args[];
       
		args = new String[11];
		args[0]="-o";
		args[1]="smartJobs.rdf";
		args[2]="-f";
		args[3]="RDF/XML";
		args[4]="-b";
		args[5]="http://www.smartJobs.com";
		args[6]="-u";
		args[7]=RuntimeSettings.dbUserID;
		args[8]="-p";
		args[9]=RuntimeSettings.dbPassword;
		args[10]=RuntimeSettings.dbUrl+RuntimeSettings.databaseName;
		
		new dump_rdf().process(args);
		System.out.println("here");
		try {
			String filePath = request.getRealPath("/rdf");
			
			File source = new File("smartJobs.rdf");
			
			File fileToCreate = new File(filePath, "smartJobs.rdf");
			System.out.println(fileToCreate.getAbsolutePath());

			FileUtils.copyFile(source, fileToCreate);
			source.delete();

		} catch (Exception ex) {
			ex.printStackTrace();
			return SUCCESS;
		}

		
		return SUCCESS;
		
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
}
